package logic

import (
	"context"
	"merchantmanager/merrpc/merrpc"

	"merchantmanager/api/internal/svc"
	"merchantmanager/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MerApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMerApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MerApiLogic {
	return &MerApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MerApiLogic) MerApi(req *types.MerRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.MerRpc.MerAdd(l.ctx, &merrpc.MerAddRequest{
		Name:  req.Name,
		Price: float32(req.Price),
		Image: req.Image,
	})
	if err != nil {
		return nil, err
	}
	return &types.Response{
		Message: "添加成功",
		Code:    200,
		Data:    add,
	}, nil
}
